package cn.cvs.dao;

import cn.cvs.pojo.Supplier;
import cn.cvs.pojo.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

//SysUserDao
//@CacheNamespace//开启注解定义的二级缓存
//不能和<cache/>同时使用
public interface SysUserMapper {
    //依据account和password查询用户
    @Select("select * from t_sys_user where account=#{account} and password=#{password}")
    SysUser queryOne(@Param("account") String account, @Param("password") String password);
    //查询所有用户
    List<SysUser> queryAll();
    //查询所有用户，使用注解
    @Select("select * from t_sys_user")
    List<SysUser> findAll();
    //依据编号查询用户
    @Select("select u.*,r.roleName"+" from t_sys_user u left join t_sys_role r"+" on u.roleId=r.id"+" where u.id=#{id}")
    @ResultMap(value = "SysUserMap")
    SysUser queryById(int id);

    SysUser findById(Integer id);

    //依据用户名RealName和角色id roleId
    List<SysUser> queryList(SysUser sysUser);

    //依据用户名RealName和角色id roleId
    List<SysUser> queryListByMap(Map<String,Object> map);
    //依据用户名RealName和角色id roleId 参数添加注解@Param
    List<SysUser> queryListByParam(@Param("realName") String realName, @Param("roleId") Integer roleId);

    //查询所有用户（包含角色名称）
    List<SysUser> queryListWithRealName();

    //resultMap查询所有用户（包含角色名称）

    //resultMap查询所有用户（包含扩展的角色对象）
    List<SysUser> queryListWithRole();

    int add(SysUser sysUser);

    int modify(SysUser sysUser);

    List<SysUser> queryAll8();

    //2021-10-26
    //if+where
    List<SysUser> queryIf(@Param("realName") String realName, @Param("roleId") Integer roleId);

    //where+choose+otherwise
    List<SysUser> queryDList(@Param("account") String account, @Param("realName") String realName, @Param("roleId") Integer roleId);

    //foreach
    List<SysUser> queryListById(@Param("ids") List<Integer> ids);
    List<SysUser> queryListById(@Param("ids") Set<Integer> ids);
    List<SysUser> queryListById(@Param("ids") Integer[] ids);
    List<SysUser> queryListById(@Param("ids") Map<String,Integer> ids);

    int update(SysUser sysUser);

    //trim查询
    List<SysUser> queryDList2(@Param("realName") String realName, @Param("roleId") Integer roleId);

    //trim修改
    int updateTrim(SysUser sysUser);

    //删除一个用户
    @Delete("delete from t_sys_user where id=#{id}")
    int deleteById(Integer id);

    List<SysUser> queryPage(@Param("pageBegin") Integer pageBegin, @Param("pageSize") Integer pageSize);

    //依据realName和roleId查询
    //分页pageBegin pageSize
    //动态SQL
    List<SysUser> queryByPage(@Param("realName") String realName, @Param("roleId") Integer roleId, @Param("pageBegin") Integer pageBegin, @Param("pageSize") Integer pageSize);

    //参与条件分页的总记录数
    int queryCount(@Param("realName") String realName, @Param("roleId") Integer roleId);

    //依据account查询用户数量
    @Select("select count(0) from t_sys_user where account=#{account}")
    int queryUserCount(@Param("account") String account);
}
